﻿
Partial Class Apps_Shares_Uc_staff_password_lock
    Inherits System.Web.UI.UserControl

    Protected Sub btnRefresh_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        gvDisplay.DataBind()
        gvDisplay.Sort("staff_no", SortDirection.Ascending)
    End Sub

    Protected Sub btnUnlockUser_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            Dim strSql As String = "UPDATE staff set staff_fail_login = 0 where staff_no in ({0})"
            Dim strStaffList As String = ""
            Dim checked As Boolean = False
            For i As Int32 = 0 To gvDisplay.Items.Count - 1 Step 1
                Dim item = gvDisplay.Items(i)
                Dim staff_no_check As CheckBox = item.FindControl("staff_no_check")
                Dim staff_no_label As Label = item.FindControl("staff_no_label")
                If staff_no_check.Checked Then
                    checked = True
                    strStaffList &= "'" & staff_no_label.Text & "', "
                End If
            Next
            If checked Then
                strStaffList = strStaffList.Substring(0, strStaffList.LastIndexOf(","))
                strSql = String.Format(strSql, strStaffList)
                ' Unlock staff
                CodeMatrix.Utilities.CodeHelper.ExecuteNonQuery(strSql)
                'Response.Write(strSql)
                ' Write log
                CodeMatrix.Business.GenericData.WriteLog("ผู้ใช้งาน " & HttpContext.Current.Session("staff_no") & " ปลดล๊อกผู้ใช้งาน " & strStaffList, 13, "U", HttpContext.Current.Session("staff_code"))
                ' Update data
                gvDisplay.DataBind()
            Else
                Throw New Exception("กรุณาเลือกผู้ใช้งานที่ต้องการปลดล๊อค")
            End If
        Catch ex As Exception
            GenericHelper.ShowAlert(Me, ex.Message)
        End Try
    End Sub

    Protected Sub gvDisplay_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewSortEventArgs) Handles gvDisplay.Sorting

        Try
            If (String.IsNullOrEmpty(e.SortExpression)) Then Return
            Dim oldSortCol As Image = gvDisplay.FindControl(gvDisplay.SortExpression)
            Dim newSortCol As Image = gvDisplay.FindControl(e.SortExpression)

            If (Not oldSortCol Is Nothing) Then oldSortCol.Visible = False
            If (Not newSortCol Is Nothing) Then
                newSortCol.Visible = True
                If e.SortDirection = SortDirection.Ascending Then
                    newSortCol.ImageUrl = "../images/btn_down.png"
                Else
                    newSortCol.ImageUrl = "../images/btn_up.png"
                End If
            End If
        Catch ex As Exception
            GenericHelper.ShowAlert(Me, ex.Message)
        End Try

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            gvDisplay.Sort("staff_no", SortDirection.Ascending)
        End If
    End Sub
End Class
